package com.af.system.api.data;

import com.af.system.api.result.AfResult;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 批量操作结果, 配合AfResult使用
 *
 * @author : zhenyun.su
 * @since : 2024/5/14
 */

public class AfDataBatch implements Serializable {
    private Integer totalCount=0;
    private Integer successCount=0;
    private Integer failureCount=0;
    private List<String> successIds = new ArrayList<>();
    private List<String> failureIds = new ArrayList<>();

    public static AfDataBatch of(Integer totalCount){
        AfDataBatch batch = new AfDataBatch();
        batch.setTotalCount(totalCount);
        return batch;
    }

    public void recordResult(AfResult<Object> result){
        if (result.getStatus()){
            successCount++;
        }else{
            failureCount++;
        }
    }
    public void recordResult(AfResult<Object> result, String id){
        if (result.getStatus()){
            successCount++;
            addSuccessId(id);
        }else{
            failureCount++;
            addFailureId(id);
        }
    }

    public void addSuccessId(String id){
        successIds.add(id);
    }

    public void addFailureId(String id){
        failureIds.add(id);
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getSuccessCount() {
        return successCount;
    }

    public void setSuccessCount(Integer successCount) {
        this.successCount = successCount;
    }

    public Integer getFailureCount() {
        return failureCount;
    }

    public void setFailureCount(Integer failureCount) {
        this.failureCount = failureCount;
    }

    public List<String> getSuccessIds() {
        return successIds;
    }

    public void setSuccessIds(List<String> successIds) {
        this.successIds = successIds;
    }

    public List<String> getFailureIds() {
        return failureIds;
    }

    public void setFailureIds(List<String> failureIds) {
        this.failureIds = failureIds;
    }

    @Override
    public String toString() {
        return "AfDataBatch{" +
                "totalCount=" + totalCount +
                ", successCount=" + successCount +
                ", failureCount=" + failureCount +
                ", successIds=" + successIds +
                ", failureIds=" + failureIds +
                '}';
    }
}
